// pages/QRCodeJump/QRCodeJump.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    orderDetail: [],
    detail: '',
    carNumber: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.carNumber = options.cph
    console.log(this.data.carNumber)
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  goindex: function () {
    var that = this
    console.log(that.data.detail.IDD)

    wx.setStorageSync('QROrderIDD', that.data.detail.IDD)
    wx.setStorageSync('isQROrder', '1')
    wx.setStorageSync('QROrderRoute', that.data.detail.Route)

    wx.switchTab({
      url: '../index/index',
    })
  },

  getData: function () {
    var that = this
    var userInfo = wx.getStorageSync('userInfo');
    console.log(userInfo)
    wx.request({
      url: 'https://www.lanshuicar.com/Server/CustS/GetOrderByCphHdl.ashx',
      data: {
        cph: that.data.carNumber,
        act: 'getd',
      },
      method: 'GET',
      success: function (res) {
        var data = res.data
        console.log(data)
        if (data.code == '0') {
          console.log('接口调用成功，code=0')
          if (data.data.length > 0) {
            console.log('有订单数据')
            //数据存入list中备用
            // that.data.orderDetail = that.data.orderDetail.concat(data.data)
            // console.log(that.data.orderDetail)

            that.setData({
              detail: data.data[0],
              carNumber: that.data.carNumber
            });

            console.log(that.data.detail)
          }
        } else {
          //返回code不为0，说明有错误
          console.log('接口调用成功，但是操作有误，返回值不为0，打印错误信息')
        }
      },
      fail: function () {
        //接口加载失败
        console.log('加载接口错误');
      }
    })
  },

  callPhone: function (e) {
    console.log(e)
    if (e.currentTarget.id == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id //仅为示例，并非真实的电话号码
    });
  },

})